#include<iostream>
#include<fstream>
#include<vector>
#include<cmath>
#include<random>
#include<string>
#include<Eigen/Dense>
std::default_random_engine generator;//使用random生成随机数
std::normal_distribution<double>distribution(0.0, 1.0);//使所有随机数的期望为0，方差为1；
void genData(const std::string& filename, int funcType, double a, double b, double c, double d)
{
    std::ofstream outFile(filename);//写入数据；
    std::vector<double>x(100), y(100);
    for (int i = 0; i < 100; i++)
    {
        x[i] = -10 + 20 * i / 99.0;
        switch (funcType)
        {
        case 1:y[i] = a * x[i] + b; break;
        case 2:y[i] = a * x[i] * x[i] + b * x[i] + c; break;
        case 3:y[i] = a * x[i] * x[i] * x[i] + b * x[i] * x[i] + c * x[i] + d; break;
        default:throw std::invalid_argument("Invalid function"); break;
        }
        y[i] += distribution(generator);//添加噪声；
        outFile << x[i] << " " << y[i] << std::endl;
    }
}